package com.smartleanx.module.hrm.dal.mysql.payroll;

import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.mybatis.core.mapper.BaseMapperX;
import com.smartleanx.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.smartleanx.module.hrm.controller.admin.payroll.vo.PayrollPageReqVO;
import com.smartleanx.module.hrm.dal.dataobject.payroll.PayrollDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;

/**
 * 薪资月份 Mapper
 *
 * @author zhangchp
 */
@Mapper
public interface PayrollMapper extends BaseMapperX<PayrollDO> {

    default PageResult<PayrollDO> selectPage(PayrollPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PayrollDO>()
                .eqIfPresent(PayrollDO::getYear, reqVO.getYear())
                .eqIfPresent(PayrollDO::getMonth, reqVO.getMonth())
                .inIfPresent(PayrollDO::getState, reqVO.getStates())
                .orderByDesc(PayrollDO::getId));
    }

    default PayrollDO selectByYearAndMonthAndState(Integer year, Integer month, Collection<Integer> states){
        return selectOne(new LambdaQueryWrapperX<PayrollDO>()
                .eq(PayrollDO::getYear, year)
                .eq(PayrollDO::getMonth, month)
                .in(PayrollDO::getState, states));
    }

    default PayrollDO selectByState(Collection<Integer> states){
        return selectOne(new LambdaQueryWrapperX<PayrollDO>().in(PayrollDO::getState, states));
    }
}